package org.asdmp.restday.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.asdmp.restday.service.RestDayService;
import org.jbpm.api.ProcessInstance;

/**
 * Servlet implementation class GetTaskController
 */
@WebServlet("/controller/getTaskController")
public class GetTaskController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetTaskController() {
        super();        
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		RestDayService.startUp();
		List<ProcessInstance> list = RestDayService.executionService.createProcessInstanceQuery().processInstanceId(RestDayService.processInstanceId).list();
		if (list != null && list.size()>0) {
			String activityName = list.get(0).findActiveActivityNames().toString();
			System.out.println("当前任务所在节点===" + activityName);
			String name = RestDayService.executionService.createProcessInstanceQuery().processInstanceId(RestDayService.processInstanceId).list().get(0).findActiveActivityNames().toString();
			request.setAttribute("responseText","当前任务所在节点========"+activityName);
			request.setAttribute("node",name);
		}
		request.getRequestDispatcher("../jsp/console.jsp").forward(request, response); 
	}

}
